import axios from 'axios'
import { MessageBox, Message } from 'element-ui'
import { getToken } from '@/utils/auth'
axios.defaults.withCredentials = false
// 设置axios的预请求
// 创建一个service的axios预请求
const service = axios.create({
  // 根据打包的线上或线下来判断请求baseURL的值
  baseURL: process.env.NODE_ENV === 'development' ? '/api' : process.env.VUE_APP_BASE_API,
  timeout: 5000
})
service.interceptors.request.use(
  config => {
    const token = getToken()
    if (token) {
      config.headers['Authorization'] = 'Bearer ' + token
    }
    return config
  },
  error => {
    return Promise.reject(error)
  }
)
export default service

// service.interceptors.response.use(
//   response => {
//     const res = response.data
//     if(response.data)
//   }
// )
